package cn.broadsense.thrid.param;

import cn.hutool.crypto.SecureUtil;
import lombok.Data;

import java.io.Serializable;

/**
 * 第二次授权参数
 *
 * @author pengxin
 * @date 2022-08-05 12:26
 */
@Data
public class SecondAuthRequest implements Serializable {

    private static final long serialVersionUID = 3550085528975983904L;

    private String clientType;

    private String encryptType = "MD5";

    private String randomKey;

    private String realm;

    private String userName;

    private String password;

    private String signature;

    private int expiredTime = 86400;

    public static String encryptPassword(String userName, String realm, String password, boolean hasBeanMd5First) {
        if (!hasBeanMd5First) {
            password = SecureUtil.md5(password);
        }
        //平台token保活示例
        return SecureUtil.md5(userName.concat(":").concat(realm).concat(":").concat(SecureUtil.md5(password)));
    }

    public static String encryptSignature(String userName, String realm, String password, String randomKey) {
        return SecureUtil.md5(SecureUtil.md5(userName.concat(":").concat(realm).concat(":").concat(password)).concat(":").concat(randomKey));
    }


}
